import express = require('express')
import redis = require('redis')

var redisClient = redis.createClient(6379,'redis');
const counter = ()=>{
    return new Promise<number>((resolve,reject)=>{
        redisClient.get('count', (_, reply) => {
            const value = reply ? parseInt(reply) + 1 : 1
            redisClient.set('count', value.toString())
            resolve(value)
        })
    })
}

const app: express.Application = express();

app.get('/', function (req, res) {
    counter().then(count=>{
        res.send(`Hello World!${count}`)
    })
})

app.listen(3000, () => {
    console.log('App listen on port 3000!')
})